//
//  LGPatientSectionView.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/2/23.
//  患者首页--区头

#import "LGPatientSectionView.h"

@interface LGPatientSectionView()

/**   */
@property (nonatomic , strong)UIImageView *tipView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UILabel *numLabel;

@end

@implementation LGPatientSectionView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

-(void)setModel:(LGPatientGroupModel *)model{
    _model = model;
    self.titleLabel.text = model.title;
    self.numLabel.text = [NSString stringWithFormat:@"%ld",model.patients.count];
}

-(void)setOpen:(BOOL)open{
    _open = open;
    CGFloat angle = (open == YES)?M_PI_2:0;
    self.tipView.transform = CGAffineTransformMakeRotation(angle);
}


-(void)openAndCloseAction{
    CGFloat angle = (self.open == YES)?0:M_PI_2;
    [UIView animateWithDuration:0.3 animations:^{
        self.tipView.transform = CGAffineTransformMakeRotation(angle);
    }];
    if(self.tapOpenAndClose){
        self.tapOpenAndClose(!self.open);
    }
}


-(void)createSubView{
    self.backgroundColor = [UIColor whiteColor];
    [self addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(openAndCloseAction)]];
    [self addSubview:self.tipView];
    [self addSubview:self.titleLabel];
    [self addSubview:self.numLabel];
    [self.tipView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(viewPix(16));
        make.width.height.equalTo(@(viewPix(12)));
        make.centerY.equalTo(self);
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.tipView.mas_right).offset(viewPix(5));
        make.centerY.equalTo(self.tipView);
    }];
    [self.numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel.mas_right).offset(viewPix(5));
        make.centerY.equalTo(self.tipView);
    }];
}
-(UIImageView *)tipView{
    if(!_tipView){
        _tipView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"患者管理-展开收起"]];
    }
    return _tipView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _titleLabel;
}

-(UILabel *)numLabel{
    if(!_numLabel){
        _numLabel = [UILabel lableWithText:@"" colorString:@"#999999" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _numLabel;
}

@end
